/**
 * @class Ext.app.XemPhieuNhapKhoPanel
 * @extends Ext.panel.Panel
 */
Ext.define('Ext.app.XemPhieuNhapKhoPanel', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.xemPhieuNhapKhoPanel',

    initComponent: function () {
        Ext.apply(this, {
            autoScroll: true,
            border: true,
            layout: 'border',
            titleAlign: 'center',
            items: [
                {
                    region: 'north',
                    xtype: 'form',
                    layout: 'hbox',
                    bodyPadding: 5,
                    bodyStyle: 'background:#ECECEC',
                    items: [{
                        xtype:'fieldset',
                        title: translations.get("HOME.TU_KHO"),
                        defaultType: 'displayfield',
                        items: [
                            {
                                fieldLabel: translations.get("HOME.TEN_KHO"),
                                labelWidth: 70,
                                maxLength: 100,
                                width: 400,
                                margin: '5 5 5 5',
                                anchor: '-5',
                                name: 'whName'
                            },
                            {
                                fieldLabel: translations.get("HOME.DIA_CHI"),
                                labelWidth: 70,
                                maxLength: 200,
                                width: 400,
                                margin: '5 5 5 5',
                                anchor: '-5',
                                name: 'whAddress'
                            },
                            {
                                fieldLabel: translations.get("HOME.PHONE"),
                                labelWidth: 70,
                                maxLength: 25,
                                width: 400,
                                margin: '5 5 5 5',
                                anchor: '-5',
                                name: 'whPhone'
                            }
                        ]
                    },{
                        xtype:'fieldset',
                        title: translations.get("HOME.DEN_KHO"),
                        defaultType: 'displayfield',
                        margin: '0 0 0 10',
                        items: [
                            {
                                fieldLabel: translations.get("HOME.TEN_KHO"),
                                labelWidth: 70,
                                maxLength: 100,
                                width: 300,
                                margin: '5 5 5 5',
                                anchor: '-5',
                                name: 'toWhName'
                            }
                        ]
                    }]
                },
                {
                    region: 'center',
                    xtype: 'gridpanel',
                    columnLines: true,
                    viewConfig: {
                        markDirty: false
                    },
                    store: {
                        fields: ['stt', 'prodPK', 'prodCode', 'tenMH', 'soKg', 'soMet', 'soKgm', 'donGiaNhap', 'thanhTien']
                    },
                    columns: [{ 
                        text: translations.get("HOME.STT"),
                        sortable: false,
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'stt',
                        width: 50
                    },{
                        text: translations.get("HOME.MA_HANG"),
                        sortable: false,
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'prodCode',
                        width: 150
                    },{
                        text: translations.get("HOME.PRODUCT_NAME_FOR_SELL"),
                        sortable: false,
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'tenMH',
                        flex: 1,
                        summaryRenderer: function(value, summaryData, dataIndex) {
                            return "T\u1ed5ng c\u1ed9ng";
                        }
                    },{
                        text: translations.get("HOME.SO_KG"),
                        sortable: false,
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'soKg',
                        align: 'right',
                        width: 80,
                        summaryType: 'sum',
                        renderer: function(value) {
                            return formatNumber(value);
                        }
                    },{
                        text: translations.get("HOME.SO_MET"),
                        sortable: false,
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'soMet',
                        width: 80,
                        align: 'right',
                        summaryType: 'sum',
                        renderer: function(value) {
                            return formatNumber(value);
                        }
                    },{
                        text: translations.get("HOME.SO_KG_MET"),
                        sortable: false,
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'soKgm',
                        align: 'right',
                        width: 80,
                        renderer: function(value) {
                            return formatNumber(value);
                        }
                    },{
                        text: translations.get("HOME.DON_GIA_NHAP"),
                        sortable: false,
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'donGiaNhap',
                        align: 'right',
                        width: 150,
                        renderer: function(value) {
                            return formatInteger(value);
                        }
                    },{
                        text: translations.get("HOME.THANH_TIEN"),
                        sortable: false,
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'thanhTien',
                        width: 150,
                        align: 'right',
                        summaryType: 'sum',
                        renderer: function(value) {
                            return formatInteger(value);
                        }
                    }],
                    features: [{
                        ftype: 'summary',
                        dock: 'bottom'
                    }]
                }
            ]            
        });
        this.callParent(arguments);
    },
    
    setData: function(obj) {
        this.down('[name=whName]').setValue(obj.whName);
        this.down('[name=whAddress]').setValue(obj.whAddress);
        this.down('[name=whPhone]').setValue(obj.whPhone);
        this.down('[name=toWhName]').setValue(obj.toWhName);
        this.down('gridpanel').getStore().add(obj.records);
    }
});
